package com.xms.form.service;

import com.xms.form.core.component.*;
import com.xms.form.entity.SystemForm;
import com.xms.utils.JsonUtil;
import com.xms.utils.UUIDUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * FormExtensions
 * </p>
 *
 * @author migo
 * @since 2021/9/9
 */
public class FormExtensions {
    // 获取表单引用的视图
    public static List<UUID> getQueryViewIds(SystemForm systemForm)
    {
        FormDescriptor form = JsonUtil.toBean(systemForm.getFormconfig(), FormDescriptor.class);
        List<UUID> result = new ArrayList<>();
        if (form.Panels != null)
        {
            //tabs
            for (PanelDescriptor tab : form.Panels)
            {
                for(SectionDescriptor sec : tab.Sections)
                {
                    for (RowDescriptor row : sec.Rows)
                    {
                        for (CellDescriptor cell : row.Cells)
                        {
                            if (cell.Control.getControlType().val() == FormControlType.SubGrid.val())
                            {
                                result.add(UUIDUtil.get(((SubGridParameters)cell.Control.getParameters()).ViewId));
                            }
                        }
                    }
                }
            }
        }
        return result;
    }
}
